import { CHANGE_LIST } from './constants'

//异步获取数据的函数
function delayData() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve([
                { id: 1, name: '钱一' },
                { id: 2, name: '李二' },
                { id: 3, name: '王三' },
            ])
        }, 2000)
    })
}



// export const getHomeList = () => dispatch => {
//     return delayData().then(list => {
//         dispatch({
//             type: CHANGE_LIST,
//             list
//         })

//         return list;
//     })
// }

export const getHomeList = () => (dispatch, getState, request) => {

    return request.get('/mock/871b3e736e653b99374b7713e4011f9f/boss/user/list')
        .then(res => {
            let userList = res.data.data.userList;
            dispatch({
                type: CHANGE_LIST,
                list: userList
            })

            return userList;
        })
}